Skip to content

Feature. Anchor navigation. Expanding print-trace util capabilities. #6

Merged
SerhiiRI merged 6 commits intomainfrom
feat-anchor-patch-print
Mar 11, 2026
Merged

Feature. Anchor navigation. Expanding print-trace util capabilities. #6
SerhiiRI merged 6 commits intomainfrom
feat-anchor-patch-print

Conversation

@SerhiiRI
Copy link
Copy Markdown
Contributor

1. Named anchors

Mark any map with "__anchor" or :__anchor, then jump to it with "@name" regardless of nesting depth. The resolver finds the nearest ancestor with that name, so duplicate anchor names are safe — each command resolves to its own closest one:

(commando/execute
  [commands-builtin/command-from-spec]
  {:items [{:__anchor "item" :price 10 :total {:commando/from ["@item" :price]}}
           {:__anchor "item" :price 20 :total {:commando/from ["@item" :price]}}]})
;; => {:items [{:__anchor "item", :price 10, :total 10}
;;             {:__anchor "item", :price 20, :total 20}]}

Anchors and "../" can be combined in one path — after jumping to the anchor, navigation continues from there:

{:commando/from ["@section" "../" :base-price]}

2. print-trace

Wraps an execution function and prints a flamegraph of all nested commando/execute calls with timing stats, instruction keys, and optional titles.

Add :__title or "__title" to the top level of any instruction to annotate that node in the flamegraph output.

Takes a zero-argument function that calls commando/execute and returns its result unchanged.

Example

(defmethod commando.commands.builtin/command-mutation :rand-n
  [_macro-type {:keys [v]}]
  (:instruction
   (commando.core/execute
     [commando.commands.builtin/command-apply-spec]
     {:commando/apply v
      := (fn [n] (rand-int n))})))

(defmethod commando.commands.builtin/command-macro :sum-n
  [_macro-type {:keys [v]}]
  {:__title "sum random"
   :commando/fn (fn [& v-coll] (apply + v-coll))
   :args [v
          {:commando/mutation :rand-n
           :v 200}]})

(print-trace
  #(commando.core/execute
     [commando.commands.builtin/command-fn-spec
      commando.commands.builtin/command-from-spec
      commando.commands.builtin/command-macro-spec
      commando.commands.builtin/command-mutation-spec]
     {:value {:commando/mutation :rand-n :v 200}
      :result {:commando/macro :sum-n
               :v {:commando/from [:value]}}}))

Output:

Printing Flamegraph for executes:
———59f2f084-28f6-44fd-bf52-1e561187a2e5
   |keys: :value, :result
   |execute-commands! 1.123606ms
   |execute           1.92817ms
   :———e4e245ca-194a-43c6-9d7e-9225e0424c46
   :   |execute-commands! 66.344µs
   :   |execute           287.669µs
   :———77de8840-c9d3-4baa-b0d6-8a9806ede29d
   :   |title: sum random
   :   |keys: :__title, :commando/fn, :args
   :   |execute-commands! 372.566µs
   :   |execute           721.636µs
   :   :———0aefeb8e-04b2-4e77-b526-6969c08f9bb5
   :   :   |execute-commands! 39.221µs
   :   :   |execute           264.591µs

@SerhiiRI SerhiiRI requested a review from Kaspazza February 24, 2026 21:33
@SerhiiRI SerhiiRI self-assigned this Feb 24, 2026
Copy link
Copy Markdown
Contributor

@Kaspazza Kaspazza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@SerhiiRI SerhiiRI merged commit 384c253 into main Mar 11, 2026
1 check passed
@SerhiiRI SerhiiRI deleted the feat-anchor-patch-print branch March 11, 2026 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants